package com.liusu.spider.test;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;

public class Active {

    /**
     * 入门程序
     */
    @Test
    public void test(){

        CloseableHttpClient client = HttpClients.createDefault();
        String url = "http://www.itcast.cn/";
        HttpGet get = new HttpGet(url);
        try {
            CloseableHttpResponse response = client.execute(get);
            if(response.getStatusLine().getStatusCode() == 200){
                HttpEntity entity = response.getEntity();
                String html = EntityUtils.toString(entity,"utf-8");
                System.out.println(html);
                response.close();
            }
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
